DevForce Help Reference
PropertyInterceptor<TInstance,TValue,TArgs> Class
Members  Example 


Type of object
Type of property value
Type of arguments to actions
Used to add custom actions to property getters and setters.
Syntax
'Declaration
 
Public Class PropertyInterceptor
    (Of TInstance,TValue,TArgs As PropertyInterceptorArgs(Of TInstance,TValue)) 
   Inherits PropertyInterceptor
public class PropertyInterceptor<TInstance,TValue,TArgs> : PropertyInterceptor 
where TArgs: PropertyInterceptorArgs<TInstance,TValue>
Type Parameters
TInstance
Type of object
TValue
Type of property value
TArgs
Type of arguments to actions
Remarks
Every EntityProperty has a GetterInterceptor, and if not returning a list of related entities, a SetterInterceptor.

Any number of PropertyInterceptorActions may be defined for each interceptor. You add these actions using attributes and AddAction(PropertyInterceptorTiming,Action<TArgs>).

You may also define PropertyInterceptors and actions on non-Entity types.

Example
public void Sample() {
     
      // Sample showing a mix of attribute and dynamic actions, on both base and derived types.
  
      // Add dynamic actions on Entity to affect any property:
      PropertyInterceptorManager.CurrentInstance.AddAction(
        new PropertyInterceptorAction<PropertyInterceptorArgs<Entity, Object>>(
          typeof(Entity),
          null,
          PropertyInterceptorMode.BeforeSet,
          (args) => Console.WriteLine("Entity BeforeSet"),
          0.0, "A"));

      PropertyInterceptorManager.CurrentInstance.AddAction(
        new PropertyInterceptorAction<PropertyInterceptorArgs<Entity, Object>>(
          typeof(Entity), 
          null,
          PropertyInterceptorMode.AfterSet,
          (args) => Console.WriteLine("Entity AfterSet"),
          0.0, "B"));

      // Look at all before set actions affecting customer company name
      foreach (var action in Customer.CompanyNameEntityProperty.SetterInterceptor.GetActions(typeof(Customer), PropertyInterceptorMode.BeforeSet)) {
        Console.WriteLine(action.Key + ", order = " + action.Order);
      }
      // Now look at all after set actions affecting customer company name
      foreach (var action in Customer.CompanyNameEntityProperty.SetterInterceptor.GetActions(typeof(Customer), PropertyInterceptorMode.AfterSet)) {
        Console.WriteLine(action.Key + ", order = " + action.Order);
      }
      
      // Now get a customer entity and set company name - see output for actions invoked.
      DomainModelEntityManager mgr = DomainModelEntityManager.DefaultManager;
      Customer c1 = mgr.Customers.First();
      c1.CompanyName = "Books N Things";
    }
    
public partial class Customer {

  [BeforeSet(Key = "CustomerBeforeAction1")]
  public void BeforeSetAnyCustomerProperty(IEntityPropertySetInterceptorArgs args) {
    Console.WriteLine("Customer any - before setting " + args.EntityProperty.Name);
  }

  [BeforeSet("CompanyName", Key = "CustomerBeforeAction2")]
  public void BeforeSetCompanyName(IEntityPropertySetInterceptorArgs args) {
    Console.WriteLine("Customer companyname - before setting company name");
  }

  [AfterSet(Key="CustomerAfterAction1")]
  public void AfterSetAnyCustomerProperty(IEntityPropertySetInterceptorArgs args) {
    Console.WriteLine("Customer any - After setting " + args.EntityProperty.Name);
  }

  [AfterSet("CompanyName", Key="CustomerAfterAction2")]
  public void AfterSetCompanyName(IEntityPropertySetInterceptorArgs args) {
    Console.WriteLine("Customer companyname - After setting company name");
  }
}
Inheritance Hierarchy

System.Object
   IdeaBlade.Core.PropertyInterceptor
      IdeaBlade.Core.PropertyInterceptor<TInstance,TValue,TArgs>

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PropertyInterceptor<TInstance,TValue,TArgs> Members
IdeaBlade.Core Namespace
PropertyInterceptorAction<TArgs> Class

Send Feedback